<?php
/**
 * Created by xun at 2021/4/26
 */

namespace console\controllers;

use common\models\c2\entity\Collection;
use common\models\c2\entity\CommissionOrder;
use common\models\c2\entity\Venue;
use common\models\c2\statics\CollectionStatus;
use common\models\c2\statics\CommissionOrderStatus;
use common\models\c2\statics\EntityDeleteStatus;
use common\models\c2\statics\VenueStatus;
use cza\base\models\statics\EntityModelState;
use yii\console\Controller;
use yii\db\Exception;
use yii\helpers\ArrayHelper;

class CommissionController extends Controller
{

    public function init()
    {
        parent::init(); // TODO: Change the autogenerated stub
    }

    public function actionIndex()
    {
        $result = CommissionOrder::find()
            ->with('collection')
            ->where(['status' => CommissionOrderStatus::STATUS_RESELLING])
            ->all();

        foreach ($result as $item) {
            /** @var $collection Collection */
            $collection = $item->collection;
            if ($collection) {
                $collection->updateAttributes(['sale_price' => $item->resell_price]);
            }
        }
    }

}